<?php
$xmlPath = 'php1001.xml';
$uId = 9;
$cate = new DOMDocument('1.0', 'utf-8');//实例化
$cate -> formatOutput = true;

if(file_exists($xmlPath)){		//尝试载入xml文件，失败跳出
	$cate->load($xmlPath);
	$isHave   = $cate->getElementsByTagName('index');//获取用户ID
	foreach ($isHave as $va){
		$userArray[] = $va->nodeValue;
	}
	print_r($userArray);
	if(in_array($uId, $userArray)){	//判断用户是否已经存在
		$result = 'aready_exist';
	}else {	//不存在就加入
		$root     = $cate->documentElement;
		$index = $cate->createElement('index');
					
		$user = $cate->createTextNode($uId);

		$index -> appendChild($user);
		$root     -> appendChild($index);
					
		$result = $cate -> save($xmlPath)?'save_success':'save_false';
	}					
}else{	//载入失败表示未创建，创建新文件
	$root	  = $cate -> createElement('root');	//创建一个标签
	$index = $cate -> createElement('index');	//创建一个标签
	
	$user     = $cate -> createTextNode($uId);		//设置标签内容
	
	$index -> appendChild($user);	//继承标签内容
	$root	  -> appendChild($index);		//继承子类
	$cate	  -> appendChild($root);
	
	$result = $cate -> save($xmlPath)?'create_success':'create_false';
}
echo $result;
echo intval(date('m'));
?>